package com.ccrfid.rmc6.repository.personnel;

import com.ccrfid.rmc6.entity.personnel.PersonnelMoveEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import java.sql.Time;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

public interface PersonnelMoveRepository extends Repository<PersonnelMoveEntity, Long> {
    //
    PersonnelMoveEntity save(PersonnelMoveEntity entity);
    //
    PersonnelMoveEntity getById(Long id);
    //
    List<PersonnelMoveEntity> getAllByPersonnelIdAndRecordTimeBetween(Long personnelId, Date start, Date end);


    @Query(nativeQuery = true, value =
            "select max(id) from personnel_move where personnel_id = :personnelId and record_time between :startTime and :endTime")
    Long getMaxId(@Param("personnelId") Long personnelId,@Param("startTime")  Date startTime,@Param("endTime") Date endTime);

    @Query(nativeQuery = true, value =
            "select min(id) from personnel_move where personnel_id = :personnelId and record_time between :startTime and :endTime")
    Long getMinId(@Param("personnelId") Long personnelId,@Param("startTime")  Date startTime,@Param("endTime") Date endTime);


    @Query(nativeQuery = true, value =
            "select max(id) from personnel_move where personnel_id = :personnelId ")
    Long getMaxIdByPersonnelId(@Param("personnelId") Long personnelId);


}
